package com.example.administrator.yuejian23.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.yuejian23.Activity.OrderDetailActivity;
import com.example.administrator.yuejian23.Bean.ClubInfo;
import com.example.administrator.yuejian23.Bean.MyOrder;
import com.example.administrator.yuejian23.Const;
import com.example.administrator.yuejian23.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/10/27.
 */

public class UserOrderAdapter extends RecyclerView.Adapter {
    private List<MyOrder> myOrders;
    private Context context;
    private LayoutInflater layoutInflater;


    private ClubInfo goButton;

    public UserOrderAdapter(Context context,List<MyOrder> myOrders){
        this.context=context;
        this.myOrders=myOrders;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View itemView=layoutInflater.from(context).inflate(R.layout.item_user_order,viewGroup,false);
        UserOrderAdapter.UserOrderViewHolder holder=new UserOrderAdapter.UserOrderViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {

        UserOrderAdapter.UserOrderViewHolder userOrderViewHolder= (UserOrderAdapter.UserOrderViewHolder) viewHolder;
       final MyOrder order=myOrders.get(position);
        if(order.getVstate().equals("0")){
            userOrderViewHolder.goButton.setText("未参加");
        }
        else {
            userOrderViewHolder.goButton.setText("已完成");
        }
        if(order.getPrice()==null){
            userOrderViewHolder.ordermoney1.setText("￥300");
        }
        else {
            ((UserOrderViewHolder) viewHolder).ordermoney1.setText("￥"+order.getPrice());
        }

        String ordernumber=order.getSignid();
        String update_time=order.getUpdate_time();
        String money=order.getPay();
        String price=order.getPrice();
        String order_name=order.getName();
        String order_pic= Const.PIC_URL+order.getThumb();
        /*String goButton=order.getVstate();*/
        userOrderViewHolder.ordernumber.setText(ordernumber);
        userOrderViewHolder.sportname.setText(order_name);
       /* userOrderViewHolder.ordermoney.setText(money);*/
      /*  userOrderViewHolder.ordermoney1.setText(price);*/
        userOrderViewHolder.ordermoney.setText(order.getPay()+"元");
        userOrderViewHolder.paytime.setText(update_time);
        /*userOrderViewHolder.goButton.setText(goButton);*/
      /*  Picasso.with(context).load(order_pic).into(userOrderViewHolder.Orderpic)*/;
        if (order.getThumb()==null){
            userOrderViewHolder.Orderpic.setImageResource(R.drawable.ic_jianshen);
        }
        else {
            Picasso.with(context).load(order_pic).into(userOrderViewHolder.Orderpic);
        }
        userOrderViewHolder.itemView.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //启动新的Activity-俱乐部详情
                Intent intent = new Intent(context, OrderDetailActivity.class);
                intent.putExtra("order_id",order.getId());
                intent.putExtra("order_type",order.getType());
                intent.putExtra("price",order.getPrice());
                context.startActivity(intent);//启动Activity的时候要注意，加context
            }
        });

    }

    @Override
    public int getItemCount() {
        return myOrders.size();
    }


    public class UserOrderViewHolder extends RecyclerView.ViewHolder{


        public TextView ordernumber;
        public ImageView Orderpic;
        public TextView ordermoney;
        public TextView sportname;
        public TextView ordermoney1;
        public TextView paytime;
        public Button goButton;
        public View itemView;

        public UserOrderViewHolder(View itemView) {
            super(itemView);
            this.itemView=itemView;
            ordernumber= (TextView) itemView.findViewById(R.id.ordernumber);
            ordermoney= (TextView) itemView.findViewById(R.id.ordermoney);
            ordermoney1= (TextView) itemView.findViewById(R.id.ordermoney1);
           sportname= (TextView) itemView.findViewById(R.id.sport_name);
            paytime= (TextView) itemView.findViewById(R.id.paytime);
            Orderpic= (ImageView) itemView.findViewById(R.id.Orderpic);
            goButton= (Button) itemView.findViewById(R.id.gobutton);
        }
    }
}

